<template>
  <div class="wrapper">
    <top :headMenu="headMenu" :topAtive="topAtive" @handTopmenu="getHandTopmenu"></top>
    <sideMenu :menuList="menuList" :defaultActive="defaultActive"></sideMenu>
    <div class="content-box" :class="{'content-collapse':collapse}">
      <div class="content">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>
<script>
import top from "../components/top";
import bus from "@/utils/bus";
import sideMenu from "../components/sideMenu";

//统一平台菜单
const baseMenu = [
  {
    icon: "el-icon-s-home",
    index: "/index",
    title: "概览"
  },
  {
    icon: "el-icon-setting",
    index: "/newsManager/list",
    title: "新闻管理"
  },
  {
    icon: "el-icon-setting",
    index: "/sys/userManager/list",
    title: "系统管理",
    subs: [
      {
        icon: "el-icon-s-home",
        index: "/sys/userManager/list",
        title: "用户管理"
      },
      {
        icon: "el-icon-setting",
        index: "/sys/roleManager/list",
        title: "角色管理"
      },
      {
        icon: "el-icon-setting",
        index: "/sys/dictionaryManager/list",
        title: "数据字典"
      }
    ]
  }
];

//系统管理菜单
const sysMenu = [
  {
    icon: "el-icon-s-home",
    index: "/sys/userManager/list",
    title: "用户管理"
  },
  {
    icon: "el-icon-setting",
    index: "/sys/roleManager/list",
    title: "角色管理"
  },
  {
    icon: "el-icon-setting",
    index: "/sys/dictionaryManager/list",
    title: "数据字典"
  }
];

const headMenu = [
  {
    name: "数字化统一平台",
    id: 1
  },
  {
    name: "系统管理",
    id: 2
  }
];
export default {
  components: {
    top,
    sideMenu
  },

  computed: {
    user() {
      return this.$store.state.user;
    }
  },
  data() {
    return {
      collapse: false,
      menuList: [],
      defaultActive: "/index",
      headMenu: [],
      topAtive: 0
    };
  },
  created() {
    console.log("当前用户", this.user);
    bus.$on("collapse", msg => {
      this.collapse = msg;
    });
    this.menuList = baseMenu;
    this.headMenu = headMenu;
  },
  methods: {

    //接受触发点击头部菜单
    getHandTopmenu(data) {
      console.log(data);
      if (data.id === 1) {
        this.menuList = baseMenu;
        this.$router.push("/");
      }
      if (data.id === 2) {
        this.menuList = sysMenu;
        this.$router.push("/sys/userManager/list");
      }
    }
  }
};
</script>
<style >
</style>
